﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Box2D.XNA;
using Spinning.Spinning.Unitity;

namespace Spinning.Spinning.Entity
{
    class PracticePlayer : Actor
    {
        
        public PracticePlayer()
        {
            Physic_Type = PhysicType.Player;
            ZIndex = Constants.player;
            UpdateHandlerListener += HowToMove;
        }

        public override void OnCreatBody(Box2D.XNA.World world, Unitity.PhysicConnectManager connectManager)
        {
            base.OnCreatBody(world, connectManager);
            Filter filter = new Filter();
            filter.categoryBits = (ushort)Constants.CategoryBitsPlayer;
            filter.maskBits = (ushort)Constants.MaskBitsPlayer;
            Filter = filter;
            _fixture.SetRestitution(0);
            _fixture.SetDensity(Constants.playerDensity);
        }

        //protected override void UpdateSelf(GameTime gameTime)
        //{
        //    base.UpdateSelf(gameTime);
        //    //HowToMove();
        //}

        public virtual void HowToMove(GameTime gameTime) 
        {
            Vector2 playVelocity = new Vector2();
            int terminalVelocity = 25;
            playVelocity.X = body.GetLinearVelocity().X + Accelerometer.X * 3f;
            playVelocity.Y = body.GetLinearVelocity().Y - Accelerometer.Y * 3f;

            if (playVelocity.X > terminalVelocity) 
                playVelocity.X = terminalVelocity;
            if (playVelocity.X < -terminalVelocity) 
                playVelocity.X = -terminalVelocity;
            if (playVelocity.Y > terminalVelocity) 
                playVelocity.Y = terminalVelocity;
            if (playVelocity.Y < -terminalVelocity) 
                playVelocity.Y = -terminalVelocity;

            body.SetLinearVelocity(playVelocity);
        }

    }
}
